package LiKouBrushQuestions;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Stack;

/**
 * 用两个栈实现队列
 *
 * @author 23737
 * 2021.9.1
 */
class main {
    public static void main(String[] args) {
        MinStack obj = new MinStack();
        obj.push(-3);
        obj.push(-0);
        obj.push(-2);
        obj.pop();
        int param_3 = obj.top();
        int param_4 = obj.min();
    }
}

class JianZhiOffer_one {
    //定义两个栈用来实现队列
    Stack<Integer> inStack;
    Stack<Integer> outStack;

    public JianZhiOffer_one() {
        inStack = new Stack<>();
        outStack = new Stack<>();
    }

    public void appendTail(int value) {
        inStack.push(value);
    }

    public int deleteHead() {
        if (outStack.empty() && inStack.empty()) {
            return -1;
        }
        if (!outStack.empty()) {
            return outStack.pop();
        }
        while (!inStack.isEmpty()) {
            outStack.push(inStack.pop());
        }
        return outStack.pop();
    }
}

/**
 * 定义栈的数据结构，请在该类型中实现一个能够得到栈的最小元素的 min 函数在该栈中
 * 调用 min、push 及 pop 的时间复杂度都是 O(1)。
 * MinStack obj = new MinStack();
 * obj.push(x);
 * obj.pop();
 * int param_3 = obj.top();
 * int param_4 = obj.min();
 */
class MinStack {
    Stack<Integer> dataStack;
    Stack<Integer> minStack;

    public MinStack() {
        dataStack = new Stack<>();
        minStack = new Stack<>();
    }

    public void push(int x) {
        if (minStack.empty() || minStack.peek()>x) {
            minStack.push(x);
        }else {
            minStack.push(minStack.peek());
        }
        dataStack.push(x);
    }

    public void pop() {
        dataStack.pop();
        minStack.pop();
    }

    public int top() {
        return dataStack.peek();
    }

    public int min() {
        return minStack.peek();
    }
}


